package com.sgz.androidlib.others;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.ailiwean.core.Result;
import com.ailiwean.core.view.style1.NBZxingView;
import com.android.sgzcommon.toast.SuToast;
import com.sgz.androidlib.others.sample.OnCodeResultListener;

/**
 * @author sgz
 * @date 2021-03-01
 */
public class SuNBZxingView extends NBZxingView {

    private OnCodeResultListener listener;

    public SuNBZxingView(Context context, AttributeSet attributeSet, int def) {
        super(context, attributeSet, def);
    }

    public SuNBZxingView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public SuNBZxingView(Context context) {
        super(context);
    }

    /**
     *
     * @param path
     */
    public void parseImageFile(String path){
        parseFile(path);
    }

    @Override
    public void resultBack(Result content) {
        if (listener != null){
            String resultText = "";
            if (content != null){
                resultText = content.getText();
            }
            listener.onResult(resultText);
        }
    }

    @Override
    protected void resultBackFile(String content) {
        if (TextUtils.isEmpty(content)){
            SuToast.showText(getContext(),"未扫描到内容");
        }
    }

    /**
     *
     * @param listener
     */
    public void setOnCodeResultListener(OnCodeResultListener listener){
        this.listener = listener;
    }

}
